package com.bdqn.bookshop.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bdqn.bookshop.entity.Notice;
import com.bdqn.bookshop.vo.NoticeVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface NoticeMapper extends BaseMapper<Notice> {


    @Select({"<script> select n.*,a.nick_name nickName from notice n INNER JOIN admin_user a on n.publisher=a.id",
            "        <where>",
            "            <if test=\"notice.title!=null and notice.title!=''\">",
            "                and title LIKE CONCAT('%',#{notice.title},'%')",
            "            </if>",
            "            <if test=\"notice.nickName!=null and notice.nickName!=''\">",
            "                and a.nick_name LIKE CONCAT('%',#{notice.nickName},'%')",
            "            </if>",
            "            <if test=\"notice.startTime!=null\">",
            "                and n.create_time <![CDATA[ >= ]]> #{notice.startTime}",
            "            </if>",
            "            <if test=\"notice.startTime!=null\">",
            "                and n.create_time <![CDATA[ <= ]]> #{notice.endTime}",
            "            </if>",
                "        </where></script>"})
    Page<Notice> selectNoice(Page<Notice> page,@Param("notice") NoticeVo noticeVo);


    @Select("select DISTINCT(DATE_FORMAT(create_time,'%Y-%m')) as ym from notice")
    List<String> selectNoiceTime();
}
